package web.fabrimind.dm.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import web.fabrimind.common.annotation.Log;
import web.fabrimind.common.core.controller.BaseController;
import web.fabrimind.common.core.domain.AjaxResult;
import web.fabrimind.common.enums.BusinessType;
import web.fabrimind.dm.domain.EquipmentAlarm;
import web.fabrimind.dm.service.IEquipmentAlarmService;
import web.fabrimind.common.utils.poi.ExcelUtil;
import web.fabrimind.common.core.page.TableDataInfo;

/**
 * 设备报警记录Controller
 * 
 * @author zhihui
 * @date 2025-03-25
 */
@RestController
@RequestMapping("/dm/alarm")
public class EquipmentAlarmController extends BaseController
{
    @Autowired
    private IEquipmentAlarmService equipmentAlarmService;

    /**
     * 查询设备报警记录列表
     */
    @PreAuthorize("@ss.hasPermi('dm:alarm:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentAlarm equipmentAlarm)
    {
        startPage();
        List<EquipmentAlarm> list = equipmentAlarmService.selectEquipmentAlarmList(equipmentAlarm);
        return getDataTable(list);
    }

    /**
     * 导出设备报警记录列表
     */
    @PreAuthorize("@ss.hasPermi('dm:alarm:export')")
    @Log(title = "设备报警记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentAlarm equipmentAlarm)
    {
        List<EquipmentAlarm> list = equipmentAlarmService.selectEquipmentAlarmList(equipmentAlarm);
        ExcelUtil<EquipmentAlarm> util = new ExcelUtil<EquipmentAlarm>(EquipmentAlarm.class);
        util.exportExcel(response, list, "设备报警记录数据");
    }

    /**
     * 获取设备报警记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('dm:alarm:query')")
    @GetMapping(value = "/{alarmId}")
    public AjaxResult getInfo(@PathVariable("alarmId") Long alarmId)
    {
        return success(equipmentAlarmService.selectEquipmentAlarmByAlarmId(alarmId));
    }

    /**
     * 新增设备报警记录
     */
    @PreAuthorize("@ss.hasPermi('dm:alarm:add')")
    @Log(title = "设备报警记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentAlarm equipmentAlarm)
    {
        return toAjax(equipmentAlarmService.insertEquipmentAlarm(equipmentAlarm));
    }

    /**
     * 修改设备报警记录
     */
    @PreAuthorize("@ss.hasPermi('dm:alarm:edit')")
    @Log(title = "设备报警记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentAlarm equipmentAlarm)
    {
        return toAjax(equipmentAlarmService.updateEquipmentAlarm(equipmentAlarm));
    }

    /**
     * 删除设备报警记录
     */
    @PreAuthorize("@ss.hasPermi('dm:alarm:remove')")
    @Log(title = "设备报警记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{alarmIds}")
    public AjaxResult remove(@PathVariable Long[] alarmIds)
    {
        return toAjax(equipmentAlarmService.deleteEquipmentAlarmByAlarmIds(alarmIds));
    }
}
